
new Vue({
    el: '#cele',
    data: {
        time:'',
        allPoples:[],
        dataTime:'',
        FireFighters:[],
        FireManInfoModel:'',
        arrOut:[]
    },
    mounted() {
        //this.restaurants = this.loadAll();
        this.FireManInfoModel = $.parseJSON(localStorage.getItem('msg'));
        console.log(this.FireManInfoModel.Fire_brigade_num)
        this.UserRoleRelationModel = $.parseJSON(localStorage.getItem('item'));
        var _Vue = this
        setInterval(function () {
            var time = new Date();
            var y = time.getFullYear();
            var m = time.getMonth() + 1;
            var d = time.getDate();
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            _Vue.time = y + '年' + _Vue.add0(m) + '月' + _Vue.add0(d) + '日  ' + _Vue.add0(h) + ':' + _Vue.add0(mm) + ':' + _Vue.add0(s);
        }, 1000)

        $('.main-left-bj ul li a').click(function () {
            //console.log(this)
            $(this).find('span').toggleClass('glyphicon-plus glyphicon-minus yellow-text')
        });

        $('body').on('click', '.fire-set-adm-name', function (e) {
            debugger
            e.stopPropagation();
            $('.fire-set-adm-name').removeClass('border')
            $(this).addClass('border')
        })
        $('body').on('click', '.fire-set-adm-name .close', function (e) {
            debugger
            e.stopPropagation();
            var c =e.target.parentNode.innerText.replace(/\s+/g,"");
            var d = {Name:c};
            // var ary=Vue.arrOut;
            for (var i = _Vue.arrOut.length-1; i>=0; i--){
                if (_Vue.arrOut[i].Name==c){
                    _Vue.arrOut.splice(i,1);
                }
            }
            var dataId=$(this).parent('.fire-set-adm-name').siblings("label").attr("dataId");
            if(dataId=='1')
            {
                var arrNum=$(this).parent('.fire-set-adm-name').attr("arrNum");
                var arr = _Vue.InsertOrUpdateCommanderDutyInfoFireList_1;
                arr.splice(arrNum,1);
                _Vue.CommanderDutyInfoSpanShow(arr,'fzr');
            }
            else if(dataId=='2')
            {
                var arrNum=$(this).parent('.fire-set-adm-name').attr("arrNum");
                var arr = _Vue.InsertOrUpdateCommanderDutyInfoFireList_2;
                arr.splice(arrNum,1);
                _Vue.CommanderDutyInfoSpanShow(arr,'txy');
            }
            else if(dataId=='3')
            {
                var Obj=$(this).parent('.fire-set-adm-name');
                var arrNum=Obj.siblings("label").attr("arrNum");
                _Vue.allPoples[arrNum]["Driver_number"]='';
                _Vue.allPoples[arrNum]["Driver_name"]='';

                Obj.attr('class', 'fire-set-adm-add').html('+')
            }
            else if(dataId=='4')
            {
                var Obj=$(this).parent('.fire-set-adm-name');
                var arrNum=Obj.siblings("label").attr("arrNum");
                var attNumber=Obj.siblings("label").attr("attNumber");
                _Vue.allPoples[arrNum]["Solider_number_"+attNumber]="";
                _Vue.allPoples[arrNum]["Solider_name_"+attNumber]="";
                _Vue.allPoples[arrNum]["Solider_type_"+attNumber]="";
                Obj.attr('class', 'fire-set-adm-add').html('+')
            }

        });
        $('body').on('click', '.fire-set-adm-add', function (e) {
            debugger
            _Vue.FireFighters=[];
            //this.ajaxGetFireFighters();
            var dataId=$(this).siblings("label").attr("dataId");
            $.ajax({
                type: 'post',
                url: Url+'/FireManApi/GetFireManListByType',
                data: JSON.stringify({ FireBrigadeNumber:_Vue.FireManInfoModel.Fire_brigade_num,FireManType:dataId }),
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if (msg.state == 1) {
                        console.log(this)
                        //根据选中过的过滤
                        var ary = msg.data;
                        // Vue.newdata= msg.data;
                        // var delid = Vue.arrOut;
                        // var arr = ary.filter(item=>{
                        //     let aaa = delid.map(v=>v.Name)
                        //     return !aaa.includes(item.Name)
                        // })
                        _Vue.FireFighters = msg.data;
                        /*newarray =  ary.filter(function(obj){
                            console.log();
                            return delid != obj.Name;
                        });
                        Vue.FireFighters = newarray*/

                    }else {

                    }

                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });

            e.stopPropagation();
            $('.fire-set-adm-add').data('active', false);
            $(this).data('active', true)
            var left = $(this).offset().left + $(this).outerWidth() + 12
            var top = $(this).offset().top - $('.dialog-selec').outerHeight() / 2 + $(this).outerHeight() / 2
            $('.dialog-selec').css({
                'top': top + 'px',
                'left': left + 'px'
            }).show()
        })
        $('.dialog-selec').on('click', 'li', function (e) {
            debugger
            var _this = this
            _Vue.arrOut.push({
                Name:_this.innerText
            })
            console.log(_Vue.arrOut)
            $('.fire-set-adm-add').each(function (index, val) {
                debugger
                if ($(val).data('active')) {
                    var dataId=$(val).siblings("label").attr("dataId");

                    if(dataId=='3')
                    {
                        var arrNum=$(val).siblings("label").attr("arrNum");
                        _Vue.allPoples[arrNum]["Driver_name"]=$(_this).attr("dataName");
                        _Vue.allPoples[arrNum]["Driver_number"]=$(_this).attr("dataNumber");
                    }
                    else if(dataId=='4')
                    {
                        var arrNum=$(val).siblings("label").attr("arrNum");
                        var attNumber=$(val).siblings("label").attr("attNumber");
                        _Vue.allPoples[arrNum]["Solider_number_"+attNumber]=$(_this).attr("dataName");
                        _Vue.allPoples[arrNum]["Solider_name_"+attNumber]=$(_this).attr("dataNumber");
                        _Vue.allPoples[arrNum]["Solider_type_"+attNumber]=attNumber;
                    }
                    else if(dataId=='2' || dataId=='1')
                    {
                        // var attNameValue=$(val).siblings("label").attr("attNameValue");
                        var jsonObj={
                            Commander_num:$(_this).attr("dataNumber"),
                            Commander_name:$(_this).attr("dataName"),
                            Commander_type:1,
                            Fire_brigade:_Vue.Fire_brigade_number,
                            Fire_brigade_name:_Vue.Fire_brigade_name,
                            Fire_number:_Vue.FireNumer,
                            Ifused:true
                        }
                        if(dataId=='1')
                        {
                            jsonObj.Commander_type=1
                            var arr=_Vue.InsertOrUpdateCommanderDutyInfoFireList_1;
                            arr.push(jsonObj)
                            Vue.CommanderDutyInfoSpanShow(arr,'fzr');
                        }
                        if(dataId=='2')
                        {
                            jsonObj.Commander_type=2
                            var arr=Vue.InsertOrUpdateCommanderDutyInfoFireList_2;
                            arr.push(jsonObj)
                            _Vue.CommanderDutyInfoSpanShow(arr,'txy');
                        }
                    }
                    $(val).attr('class', 'fire-set-adm-name')
                    $(val).html($(_this).text() + '<img src="../images/close.png" class="close"/>')
                }
                //获取id中缩带下标
                $('.dialog-selec').hide()
            })
            e.stopPropagation();
        })

        //  存储信息
      /*  _Vue.FireManInfoModel = $.parseJSON(localStorage.getItem('msg'));
        console.log(_Vue.FireManInfoModel)
        _Vue.UserRoleRelationModel = $.parseJSON(localStorage.getItem('item'));
        var a =  _Vue.FireManInfoModel;
        var b = _Vue.UserRoleRelationModel;*/
      this.ajaxdata()
    },
    computed:{

    },
    methods:{
        ajaxdata(){
            var Vue = this
            $.ajax({
                type: 'post',
                url: Url+'NormalDutyApi/GetNormalVehicleDutyInfo',
                data: JSON.stringify({BrigadeNumber:Vue.FireManInfoModel.Fire_brigade_num,Date:Vue.dataTime}),//中队编号
                dataType:'json',
                contentType: 'application/json',
                success: function (msg) {
                    if(msg.state==1){
                        Vue.allPoples = msg.data
                    }else {
                        Vue.$message.error('新增失败')
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            })
        },
        //获取当前时间，格式YYYY-MM-DD
        getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            this.dataTime = year + seperator1 + month + seperator1 + strDate;
            return this.dataTime;
        },
        add0(m){
            return m<10?'0'+m:m
        },
        Quit(){
            $.cookie('token', '',{ expires: -1 ,path: '/' });
            window.location.href='../login.html'
        }
    }

})
